home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BMUG Revelations
/
BMUG Revelations.toast
/
Utilities
/
Text and Speech
/
BBEdit 2.2.2
/
BBEdit Extensions
/
Sources
/
EducateQuotes.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-27
|
1KB
|
90 lines
#include <SetupA4.h>
#include "ExternalInterface.h"
static Boolean quote_breaks[256];
static void init_quote_breaks(void)
{
short i;
for (i = 0; i < 256; i++)
quote_breaks[i] = FALSE;
quote_breaks['\t'] = TRUE;
quote_breaks['\r'] = TRUE;
quote_breaks[0x00CA] = TRUE;
quote_breaks[' '] = TRUE;
quote_breaks['('] = TRUE;
quote_breaks['{'] = TRUE;
quote_breaks['['] = TRUE;
quote_breaks[0x00D2] = TRUE;
quote_breaks[0x00D4] = TRUE;
}
pascal void main(ExternalCallbackBlock *callbacks, WindowPtr w)
{
Handle h;
long i, len;
Boolean changed = FALSE;
register unsigned char c;
register unsigned char *p;
RememberA0();
SetUpA4();
changed = FALSE;
h = callbacks->GetWindowContents(w);
asm
{
movea.l h, a0
_GetHandleSize
move.l d0, len
}
init_quote_breaks();
callbacks->StartProgress("\pConverting Quotes…", len, FALSE);
p = (unsigned char *)*h;
for (i = 0; i < len; i++)
{
callbacks->DoProgress(i);
c = *p;
if ((i == 0) || quote_breaks[p[-1]])
{
if (c == '"')
c = '“';
else if (c == '\'')
c = '‘';
}
else
{
if (c == '"')
c = '”';
else if (c == '\'')
c = '’';
}
if (c != *p)
{
*p = c;
changed = TRUE;
}
p++;
}
callbacks->DoneProgress();
if (changed)
callbacks->ContentsChanged(w);
RestoreA4();
}